<?php

class TBMXoaDeTai extends BaseController {

    public function index() {
        $id_hknk = DB::select(DB::raw('call get_hknk(null,null);'));
        if (Input::has('txtHocKy')) {
            $nk = Input::get('txtNienKhoa');
            $hk = Input::get('txtHocKy');
            $idhknk = DB::select(DB::raw("call get_hknk('" . $hk . "','" . $nk . "');"));
            if (count($idhknk) != 0) {
                $id_hknk = $idhknk;
            }
        }
        return View::make('truongbomon.xoadt')->with('title', 'Xóa đề tài chưa được đăng ký')->with('idhknk', $id_hknk);
    }

    public function show($id_bo_mon, $id) {
        $array_de_tais = DB::select(DB::raw("call get_ds_lv_can_xoa(" . $id . "," . $id_bo_mon . ");"));
        return $array_de_tais;
    }

    public function edit($id) {
        $de_tai = DB::select(DB::raw("call get_de_tai_chi_tiet_xoa(" . $id . ");"));
        return View::make('truongbomon.xemdt')
                        ->with('title', 'Xem chi tiết đề tài chưa đăng ký')
                        ->with('de_tai', $de_tai);
    }

    public function destroy() {
        $id = Input::get('txtIdDeTai');
        $tv = Input::get('txtTacVu');
        if ($tv == 'true') {
            $tv = 0;
        } else {
            $tv = 1;
        }
        $result = DB::statement(DB::raw("call xoa_mem_de_tai(" . $id . "," . $tv . ");"));
        return Redirect::back()->with('result', $result);
    }

    public function delete() {
        $id = Input::get('txtIdDeTai');
        $result = DB::statement(DB::raw("call xoa_cung_de_tai(" . $id . ");"));
        return Redirect::to('/tbm/6/xoadt');
    }
}
